Public Class BlackBerry_AddUser
    Inherits [lib].BasePage

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents txt_userid As System.Web.UI.WebControls.TextBox
    Protected WithEvents btn_add As System.Web.UI.WebControls.Button
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents grw_user As System.Web.UI.WebControls.DataGrid
    Protected WithEvents proc As System.Web.UI.HtmlControls.HtmlInputHidden

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Me.PageTitle = "BlackBerry Add User"

        Dim Vproc As String
        Vproc = Me.proc.Value
        Me.proc.Value = ""
        If Vproc = "" Then
            Vproc = "tree"
        End If

        Select Case Vproc
            Case "geri"
                Response.Redirect("BlackBerry_Main_New.aspx")
        End Select

        If Not Me.IsPostBack Then
            Fill_Form()
        End If
    End Sub

    Private Sub Fill_Form()

        Dim query As String = "select b.USERID USER_ID, c.USERNAME USER_NAME from blackberry.blackberry_granted_users b, login_user c " & _
                         "where b.UserID = c.UserID order by c.USERNAME"

        grw_user.DataSource = persistent.myDBConn.myORATable(query)
        grw_user.DataBind()

    End Sub

    Private Sub btn_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_add.Click
        Dim query As String = Nothing
        Dim username As String = Nothing
        Dim userid As String = txt_userid.Text

        'billingnette bu user var mi
        If (userid.Trim = "") Then
            Label1.Text = "Userid alani bos olamaz."
        Else
            query = "select COUNT (*) from login_user where USERID = '" & userid & "'"
            Dim is_user_exist_in_bilingnet = CType(persistent.myDBConn.ORAScalar(query), Integer)

            query = "select COUNT (*) from blackberry.blackberry_granted_users where USERID = '" & userid & "'"
            Dim is_user_exist_in_blackberry = CType(persistent.myDBConn.ORAScalar(query), Integer)

            If (is_user_exist_in_blackberry) Then
                Label1.Text = "Bu kullanici zaten tanimli."
            ElseIf is_user_exist_in_bilingnet = 0 Then
                Label1.Text = "Kullanici Billingnet te tanimli degil."
            Else

                query = "insert into blackberry.blackberry_granted_users values ('" & userid & "')"

                persistent.myDBConn.ORAExecute(query)
                Label1.Text = "Kullanici eklenmistir."

                Fill_Form()
            End If
        End If



    End Sub

    Private Sub DataGrid1_DeleteCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grw_user.DeleteCommand

        Dim userid As String = e.Item.Cells(0).Text


        Dim query As String = "delete from blackberry.blackberry_granted_users where USERID = '" & userid & "'"
        persistent.myDBConn.ORAExecute(query)

         Fill_Form()

        Label1.Text = userid & " kullanicisi silinmistir."

    End Sub

    'Public Sub DeleteUser(ByVal sender As Object, ByVal args As CommandEventArgs)
    '    Dim userid As String = args.CommandArgument

    '    Dim query As String = "delete from billintra.retention_users where USER_ID = '" & userid & "'"
    '    persistent.myDBConn.ORAExecute(query)

    '    grw_user.DataSource = persistent.myDBConn.myORATable("select * from billintra.retention_users")
    '    grw_user.DataBind()

    'End Sub

    'Private Sub grw_user_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles grw_user.DataBinding

    '    Dim LinkButton1 As LinkButton
    '    For Each row As DataGridItem In grw_user.Items
    '        LinkButton1 = CType(row.Cells(3).Controls(0), LinkButton)
    '        LinkButton1.Attributes.Add("onclick", "javascript:return confirm('Halil OK e bas')")
    '    Next
    'End Sub

    'Private Sub grw_user_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grw_user.ItemDataBound
    '    Dim LinkButton1 As LinkButton = CType(e.Item.Cells(3).FindControl("lbtnDelete"), LinkButton)
    '    LinkButton1.Attributes.Add("onclick", "javascript:return confirm('Halil OK e bas')")
    'End Sub

    'Private Sub grw_user_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grw_user.ItemCreated

    'End Sub
End Class
